package io.renren.com.qywt.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.commons.mybatis.service.impl.CrudServiceImpl;
import io.renren.com.qywt.dao.AftersaleMultiNumDao;
import io.renren.com.qywt.dto.AftersaleMultiNumDTO;
import io.renren.com.qywt.entity.AftersaleMultiNumEntity;
import io.renren.com.qywt.service.AftersaleMultiNumService;
import io.renren.commons.tools.utils.ConvertUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 退货商品(多品)名称及数量
 *
 * @author jiaohj 15110414840@139.com
 * @since 3.0 2022-09-26
 */
@Service
public class AftersaleMultiNumServiceImpl extends CrudServiceImpl<AftersaleMultiNumDao, AftersaleMultiNumEntity, AftersaleMultiNumDTO> implements AftersaleMultiNumService {

    @Override
    public QueryWrapper<AftersaleMultiNumEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<AftersaleMultiNumEntity> wrapper = new QueryWrapper<>();
        Long returnGoodId= (Long) params.get("returnGoodId");
        wrapper.eq(ObjectUtil.isNotNull(returnGoodId),"return_good_id",returnGoodId);
        return wrapper;
    }


    @Override
    public List<AftersaleMultiNumDTO> getByReturnGoodId(Long returnGoodId) {
        Map<String, Object> params=new HashMap<>();
        params.put("returnGoodId",returnGoodId);
        return ConvertUtils.sourceToTarget(baseDao.selectList(this.getWrapper(params)),AftersaleMultiNumDTO.class);
    }

    @Override
    public int deleteByReturnGoodId(Long returnGoodId) {
        Map<String, Object> params=new HashMap<>();
        params.put("returnGoodId",returnGoodId);
        return baseDao.delete(this.getWrapper(params));
    }
}